package com.ruoyi.zxjd.work.service.impl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.zxjd.work.domain.WorkProgress;
import com.ruoyi.zxjd.work.domain.WorkTemplateTable1;
import com.ruoyi.zxjd.work.domain.bo.WorkProgressBO;
import com.ruoyi.zxjd.work.mapper.WorkTemplateTable1Mapper;
import com.ruoyi.zxjd.work.service.IWorkTemplateTable1Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 信息报送情况统计Service业务层处理
 * 
 * @author lcc
 * @date 2021-02-22
 */
@Service
public class WorkTemplateTable1ServiceImpl implements IWorkTemplateTable1Service 
{
    @Autowired(required = false)
    private WorkTemplateTable1Mapper workTemplateTable1Mapper;

    @Autowired
    private WorkProgressServiceImpl workProgressService;

    /**
     * 查询信息报送情况统计
     * 
     * @param id 信息报送情况统计ID
     * @return 信息报送情况统计
     */
    @Override
    public WorkTemplateTable1 selectWorkTemplateTable1ById(Long id)
    {
        return workTemplateTable1Mapper.selectWorkTemplateTable1ById(id);
    }

    /**
     * 查询信息报送情况统计列表
     * 
     * @param workTemplateTable1 信息报送情况统计
     * @return 信息报送情况统计
     */
    @Override
    public List<WorkTemplateTable1> selectWorkTemplateTable1List(WorkTemplateTable1 workTemplateTable1)
    {
        return workTemplateTable1Mapper.selectWorkTemplateTable1List(workTemplateTable1);
    }

    /**
     * 新增信息报送情况统计
     * 
     * @param workTemplateTable1 信息报送情况统计
     * @return 结果
     */
    @Override
    @Transactional
    public int insertWorkTemplateTable1(WorkProgressBO workProgressBO)
    {
        WorkProgress workProgress = workProgressBO.getWorkProgress();
        workTemplateTable1Mapper.deleteByProgressId(workProgress.getProgressId());
        List<WorkTemplateTable1> workTemplateTable1List = workProgressBO.getWorkTemplateTable1List();
        for (WorkTemplateTable1 table : workTemplateTable1List) {
            table.setCreateBy(ShiroUtils.getLoginName());
            table.setCreateTime(DateUtils.getNowDate());
            table.setProgressId(workProgress.getProgressId());
            workTemplateTable1Mapper.insertWorkTemplateTable1(table);
        }
        return workProgressService.validate(workProgress);
    }

    /**
     * 修改信息报送情况统计
     * 
     * @param workTemplateTable1 信息报送情况统计
     * @return 结果
     */
    @Override
    public int updateWorkTemplateTable1(WorkTemplateTable1 workTemplateTable1)
    {
        workTemplateTable1.setUpdateBy(ShiroUtils.getLoginName());
        workTemplateTable1.setUpdateTime(DateUtils.getNowDate());
        return workTemplateTable1Mapper.updateWorkTemplateTable1(workTemplateTable1);
    }

    /**
     * 删除信息报送情况统计对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteWorkTemplateTable1ByIds(String ids)
    {
        return workTemplateTable1Mapper.deleteWorkTemplateTable1ByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除信息报送情况统计信息
     * 
     * @param id 信息报送情况统计ID
     * @return 结果
     */
    @Override
    public int deleteWorkTemplateTable1ById(Long id)
    {
        return workTemplateTable1Mapper.deleteWorkTemplateTable1ById(id);
    }

    /**
     * 查询信息报送情况统计
     * 
     * @param progressId
     * @return 信息报送情况统计
     */
    @Override
    public List<WorkTemplateTable1> selectWorkTemplateTable1ByProgressId(Long progressId) {
        return workTemplateTable1Mapper.selectWorkTemplateTable1ByProgressId(progressId);
    }

    /**
     * 查询信息报送情况统计
     * 
     * @param arrangeId
     * @return 信息报送情况统计
     */
    @Override
    public List<WorkTemplateTable1> selectWorkTemplateTable1ByArrangeId(Long arrangeId) {
        return workTemplateTable1Mapper.selectWorkTemplateTableByArrangeIdAndStatus(arrangeId);
    }

}